<template>
    <div class="app-container">
        <div class="block">
            <el-row>
                <el-col :span="24">
                    <el-button type="success" size="mini" icon="el-icon-plus" @click.native="add" v-permission="['/category/edit']">{{ $t('button.add') }}</el-button>
                    <el-button type="danger" size="mini" icon="el-icon-edit" @click.native="update">{{ $t('button.edit') }}</el-button>
                    <el-button type="danger" size="mini" icon="el-icon-delete" @click.native="remove">{{ $t('button.delete') }}</el-button>
                </el-col>
            </el-row>
        </div>

        <el-table :data="allHotClassList" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row @current-change="handleCurrentChange" @row-click="clickRow">
            <el-table-column label="一级分类">
                <template slot-scope="scope">{{scope.row.first}}</template>
            </el-table-column>
            <el-table-column label="二级分类">
                <template slot-scope="scope">{{scope.row.second}}</template>
            </el-table-column>
            <el-table-column label="图标">
                <template slot-scope="scope">
                    <div>
                        <el-avatar :src="scope.row.icon"></el-avatar>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="排序">
                <template slot-scope="scope">{{scope.row.hotSort}}</template>
            </el-table-column>
        </el-table>

        <el-dialog :title="addFormTitle" :visible.sync="addFormVisible" width="70%">
            <el-form ref="form" :model="addForm" label-width="150px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="一级分类">
                            <el-select :change="firstClassChange()" v-model="addForm.id" placeholder="请选择">
                                <el-option v-for="item in allFirstClassList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="二级分类">
                            <el-select v-model="addForm.secondId" placeholder="请选择">
                                <el-option v-for="item in allSecondClassList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="save">{{ $t('button.submit') }}</el-button>
                    <el-button @click.native="addFormVisible = false">{{ $t('button.cancel') }}</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog :title="updateFormTitle" :visible.sync="updateFormVisible" width="70%">
            <el-form ref="form" :model="updateForm" label-width="150px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="一级分类">
                            <el-select v-model="updateForm.first" disabled></el-select>
                        </el-form-item>
                        <el-form-item label="二级分类">
                            <el-select v-model="updateForm.second" disabled></el-select>
                        </el-form-item>
                        <el-form-item label="排序">
                            <el-input v-model="updateForm.hotSort" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="updateHotSort">{{ $t('button.submit') }}</el-button>
                    <el-button @click.native="updateFormVisible = false">{{ $t('button.cancel') }}</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script src="./hotCategorySetting.js"></script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>

